/*
 *
 *   Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *   WSO2 Inc. licenses this file to you under the Apache License,
 *   Version 2.0 (the "License"); you may not use this file except
 *   in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 * /
 */

package org.wso2.carbon.integration.test.outputflow;

import org.wso2.cep.integration.common.utils.CEPIntegrationTest;

/**
 * Sending different from the Websocket and websocket local publishers
 */
public class UIAdapterTestCase extends CEPIntegrationTest {

//    private static final Log log = LogFactory.getLog(UIAdapterTestCase.class);
//
//    @BeforeClass(alwaysRun = true)
//    public void init()
//            throws Exception {
//
//        super.init(TestUserMode.SUPER_TENANT_ADMIN);
//        String loggedInSessionCookie = getSessionCookie();
//
//        eventSimulatorAdminServiceClient = configurationUtil.getEventSimulatorAdminServiceClient(backendURL, loggedInSessionCookie);
//        eventStreamManagerAdminServiceClient = configurationUtil.getEventStreamManagerAdminServiceClient(backendURL, loggedInSessionCookie);
//        eventPublisherAdminServiceClient = configurationUtil.getEventPublisherAdminServiceClient(backendURL, loggedInSessionCookie);
//    }
//
//    @Test(groups = {"wso2.cep"}, description = "Testing UI publisher with Websocket and wso2event formatted event")
//    public void uiWebsocketReceiver() throws Exception {
//
//        int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
//        int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();
//        String samplePath = "outputflows" + File.separator + "sample0071";
//
//        //Add StreamDefinition
//        String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath,
//                                                                       "org.wso2.event.sensor.stream_1.0.0.json");
//        eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
//        Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);
//
//        //Add UI wso2event EventPublisher
//        String eventPublisherConfig = getXMLArtifactConfiguration(samplePath,
//                                                                  "uiPublisher.xml");
//        eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
//        Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);
//
//        WebSocketClient webSocketClient = new WebSocketClient();
//        webSocketClient.receive("ws://localhost:" + CEPIntegrationTestConstants.HTTP_PORT +
//                                "/outputui/org.wso2.event.sensor.stream/1.0.0", 30);
//
//        Thread.sleep(1000);
//
//        EventDto eventDto = new EventDto();
//        eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
//        eventDto.setAttributeValues(new String[]{"199008131245", "false", "100", "temperature", "23.45656",
//                                                 "7.12324", "100.34", "23.4545"});
//
//        eventSimulatorAdminServiceClient.sendEvent(eventDto);
//        Thread.sleep(1000);
//
//        eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
//        eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("uiPublisher.xml");
//
//        Assert.assertNotNull(webSocketClient.getReceivedMessage(), "No message received from ui");
//    }
//
//    @Test(groups = {"wso2.cep"}, description = "Testing UI publisher with Http and wso2event formatted event")
//    public void uiHttpReceiver() throws Exception {
//
//        int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount();
//        int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount();
//        String samplePath = "outputflows" + File.separator + "sample0071";
//
//        //Add StreamDefinition
//        String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath,
//                                                                       "org.wso2.event.sensor.stream_1.0.0.json");
//        eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString);
//        Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1);
//
//        //Add UI wso2event EventPublisher
//        String eventPublisherConfig = getXMLArtifactConfiguration(samplePath,
//                                                                  "uiPublisher.xml");
//        eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig);
//        Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1);
//
//        EventDto eventDto = new EventDto();
//        eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0");
//        eventDto.setAttributeValues(new String[]{"199008131245", "false", "100", "temperature", "23.45656",
//                                                 "7.12324", "100.34", "23.4545"});
//
//        eventSimulatorAdminServiceClient.sendEvent(eventDto);
//        Thread.sleep(1000);
//
//        HttpEventReceiverClient httpEventReceiverClient = new HttpEventReceiverClient();
//        httpEventReceiverClient.receive("http://localhost:" + CEPIntegrationTestConstants.HTTP_PORT + "/outputui/org.wso2" +
//                                        ".event.sensor.stream/1.0" +
//                                        ".0?lastUpdatedTime=-1", "GET");
//
//        Thread.sleep(1000);
//
//        eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0");
//        eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("uiPublisher.xml");
//
//        Assert.assertNotNull(httpEventReceiverClient.getReceivedMessage(), "No Http response message received from ui");
//    }
//
//    @AfterClass(alwaysRun = true)
//    public void destroy() throws Exception {
//        super.cleanup();
//    }
}
